define(() => {
    const util = {

        ..._,

        isDefined(value) {
            return !util.isUndefined(value);
        },

        isURL(value) {
            return util.isString(value) && /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/.test(value);
        },

        isHexColor(value) {
            return util.isString(value) && /^\#[0-9a-zA-Z]{3,6}$/.test(value);
        },

        assert(expression, error) {
            if(!expression)
                throw util.isError(error) ? new error : new Error(error);
        },

        instanceInject(instance, data = {}, plans = []) {
            if(!util.isObject(instance))
                throw new TypeError("instance type must be Instance");
            if(!util.isObject(data))
                throw new TypeError("data type must be Object");
            if(!util.isArray(plans))
                throw new TypeError("plans type must be Array");
            plans.forEach((plan, index) => {
                try {
                    const [required, key, initValue] = plan;
                    if(!util.isBoolean(required))
                        throw new TypeError("required type must be Boolean");
                    if(util.isUndefined(data[key])) {
                        if(required)
                            throw new Error(`required param ${key} not found`);  //如果是必须参数则抛出错误
                        if(util.isDefined(initValue))
                            instance[key] = initValue;  //非必须参数设置初始值
                        return;
                    }
                    if(!util.isString(key))
                        throw new TypeError("key type must be String");
                    instance[key] = data[key];  //给实例的数据赋值
                }
                catch(err) {
                    logger.error(`injectPlan[${index}] -> [${plans[index]}]`, err);
                    throw new Error("param mismatch");
                }
            });
        }

    };
    return util;
});